package sys.person;

import sys.database.Database;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import static sys.util.EventUtil.getNameOfEventByID;

public class TeaAndStu extends AbstractPerson{

    public TeaAndStu(String id, String name) {
        super(id, name);
    }

    // OK
    public void participateEvent(String eventID) {
        String sql = "insert into player (playerID, playerName, eventID, eventName, Score) values (?, ?, ?, ?, ?)";
        PreparedStatement preparedStatement = new Database().createConnection(sql);

        try {
            preparedStatement.setString(1, getId());
            preparedStatement.setString(2, getName());
            preparedStatement.setString(3, eventID);
            preparedStatement.setString(4, getNameOfEventByID (eventID));
            preparedStatement.setDouble(5, 0.0);
            preparedStatement.executeUpdate();
        } catch (SQLException e) {
            System.out.println("项目报名失败！");
        }
    }

    // OK
    public void becomeJudge(String eventID) {
        String sql = "insert into judge (judgeID, judgeName, eventID, eventName) values (?, ?, ?, ?)";
        PreparedStatement preparedStatement = new Database().createConnection(sql);

        try {
            preparedStatement.setString(1, getId());
            preparedStatement.setString(2, getName());
            preparedStatement.setString(3, eventID);
            preparedStatement.setString(4, getNameOfEventByID (eventID));
            preparedStatement.executeUpdate();
        } catch (SQLException e) {
            System.out.println("报名项目裁判失败！");
        }
    }

    // OK
    public void becomeVolunteer(String eventID) {
        String sql = "insert into volunteer (volunteerID, volunteerName, eventID, eventName) values (?, ?, ?, ?) ";
        PreparedStatement preparedStatement = new Database().createConnection(sql);

        try {
            preparedStatement.setString(1, getId());
            preparedStatement.setString(2, getName());
            preparedStatement.setString(3, eventID);
            preparedStatement.setString(4, getNameOfEventByID (eventID));
            preparedStatement.executeUpdate();
        } catch (SQLException e) {
            System.out.println("报名项目裁判失败！");
        }
    }
}
